$(function(){
    //为用户名
    var flag = false;
    $('input#username').on({
        'focus': function () {
            var $username = $("input#username").val();
            var regex = /^[\u4E00-\u9FA5A-Za-z0-9_-]*$/;
            if (!regex.test($username) || ($username.length<4 || $username.length>20) || !isNaN($.trim($username))) {
                $(".user-tip i").removeClass("user-error-error");
                $(".user-tip i").removeClass("user-error-errors");
                $(".user-tip i").addClass("user-error-help");
                $("span#usernam_error").css("color","#ddd");
                $("span#usernam_error").html("支持中文、字母、数字、\"_\" 的组合，4-20个字符");
            }else if($.trim($username) == "") {
                $("span#usernam_error").html("支持中文、字母、数字、\"_\" 的组合，4-20个字符");
                $(".user-tip i").removeClass("user-error-errors");
                $(".user-tip i").addClass("user-error-help");
            }
            else{
                $("#username").css("border","1px solid #ddd");
                $("span#usernam_error").css("color","#ddd");
                $(".user-tip i").removeClass("user-error-errors");
                $(".user-tip i").addClass("user-error-help");
                $("span#usernam_error").html("支持中文、字母、数字、\"_\" 的组合，4-20个字符");
            };

        },
         'blur': function () {
            var $username = $("input#username").val();
            var regex = /^[\u4E00-\u9FA5A-Za-z0-9_-]{4,20}$/;
            if ($.trim($username) == "") {
                $("span#usernam_error").html("");
                $(".user-tip i").removeClass("user-error-error");
                $(".user-tip i").removeClass("user-error-help");
            }else {
                if(!/^[\u4E00-\u9FA5A-Za-z0-9_-]*$/.test($username)){
                    $(".user-tip i").addClass("user-error-error");
                    $("span#usernam_error").html("格式错误、仅支持中文、字母、数字、\"_\" 的组合，4-20个字符");
                }else if ($.trim($username).length<4 || $.trim($username).length>20) {
                    $("span#usernam_error").html("长度只能在4-20个字符之间");
                    $(".user-tip i").addClass("user-error-error");
                }else if(!isNaN($.trim($username))){
                    $(".user-tip i").addClass("user-error-error");
                    $("span#usernam_error").html("用户名不能是纯数字，请重新输入");
                }else{
                    $("span#usernam_error").html("");
                    $(".msg-user-icon").css("display","block");
                    $(".user-tip i").removeClass("user-error-help");
                    flag = true;
					$.ajax({ 
				        type:"GET",
				        dataType:"json",
				        url:'http://192.168.0.16:8080/eLink/user/checkUsername/'+$username,
				        beforeSend: function () {
							$(".msg-user-icon").css("display","none");							
						},
				        success: function(result) {
				        	//alert(result.rtnCode);
				            //document.write(JSON.stringify(result));
				           // alert(result.username);
				            if(result.rtnCode == 1000) {
				            	$("#username").css("border","1px solid #ddd");
			 					$("span#usernam_error").css("color","#ddd");
								$(".user-tip i").removeClass("user-error-errors"); 
								$(".msg-user-icon").css("display","block");
				                //alert(result.rtnMessage);
				            } else  {
				            	//if (result.requestSuccess != 1000)
				                //alert(result.rtnMessage);
				                alert("1");
				                $("#username").css("border","1px solid red");
			 					$("span#usernam_error").css("color","red");			 					
								$(".user-tip i").addClass("user-error-error");
								$("span#usernam_error").html("用户名已经被占用，请重新注册");
				            }
				        },
				         error:function(jqXHR){     
				           alert("发生错误：" + jqXHR.status)  
				        }  
		    		});    
	
                };                
                if(!regex.test($username)|| !isNaN($.trim($username))){
                $("#username").css("border","1px solid red");
                $("span#usernam_error").css("color","red");
                $(".msg-user-icon").css("display","none");
                $(".user-tip i").addClass("user-error-error");
                }                
            }
        },
        'keyup': function () {
            var $username = $("input#username").val();
         if (!/^[\u4E00-\u9FA5A-Za-z0-9_-]*$/.test($username)) {
                $(".user-tip i").addClass("user-error-error");
                $("span#usernam_error").html("格式错误、仅支持中文、字母、数字、\"_\" 的组合，4-20个字符");
                $("#username").css("border","1px solid red");
                $("span#usernam_error").css("color","red");
                $(".msg-user-icon").css("display","none");
                $(".user-tip i").addClass("user-error-error");
            }else{
                $("#username").css("border","1px solid #ddd");
                $("span#usernam_error").css("color","#ddd");
                $(".msg-user-icon").css("display","none");
                $("span#usernam_error").html("支持中文、字母、数字、\"_\" 的组合，4-20个字符");
                $(".user-tip i").addClass("user-error-help");
                $(".user-tip i").removeClass("user-error-error");
            };
        }    
    });
    
    //密码
    var flag2 = false;
    $('input#password').on({
        'focus': function () {
            var $password = $("input#password").val();
            var regex = /^[\u4E00-\u9FA5A-Za-z0-9_-]*$/;
            if (!$.trim($password) == "") {
                $(".paw-tip i").addClass("user-error-help");
            }else{
                $("#password").css("border","1px solid #ddd");
                $("span#password_error").css("color","#ddd");
                $("span#password_error").html("建议使用字母，数字和符号两种以上组合，6-20个字符");
                $(".paw-tip i").removeClass("icon-w");
                $(".paw-tip i").addClass("user-error-help");               
            };          
        },
         'blur': function () {
            var $password = $("input#password").val();
            var regex = /^[A-Za-z]*$/;
            if ($.trim($password) == "") {
                $("span#password_error").html("");
                $(".paw-tip i").removeClass("user-error-help");
                $(".paw-tip i").removeClass("user-error-error");
            }else {
                flag2 = true;
                if(!isNaN($.trim($password)) || regex.test($password)){
                    if ($.trim($password).length<6 || $.trim($password).length>20){
                        $("span#password_error").html("长度只能在6-20个字符之间");
                        $("#password").css("border","1px solid red");
                        $("span#password_error").css("color","red");
                        $(".paw-tip i").addClass("user-error-error");
                    }else if((!isNaN($.trim($password)) && $.trim($password).length>10) || (regex.test($password) && $.trim($password).length>10)){
                        $("span#password_error").html("有被盗风险,建议使用字母、数字和符号两种及以上组合");
                        $("#password").css("border","1px solid #ddd");
                        $("span#password_error").css("color","#ddd");
                        $(".paw-tip i").addClass("user-error-w");
                        flag2 = true;
                    }
                    else if(!isNaN($.trim($password)) || regex.test($password)){
                        $("span#password_error").html("有被盗风险,建议使用字母、数字和符号两种及以上组合");
                        $("#password").css("border","1px solid red");
                        $("span#password_error").css("color","red");
                        $(".paw-tip i").addClass("user-error-w");
                         flag2 = true;             
                    }                    
                }                   
            }           
        },
        'keyup': function () {
            var $password = $("input#password").val();
                reg1 = /^[0-9]+$/,  
                reg2 = /^[a-zA-Z]+$/, 
                reg3 = /^[a-zA-Z0-9]+$/,  
                reg4=/[~!@#\$%^&*\(\)\{\};,.`\?\/'"]+[A-Z0-9a-z_ ]+/;  //reg4 = /^[a-zA-Z0-9!@#$%^&*()_+-=]+$/, 
            if ($password.length >= 6) {
                    if(reg1.test($password) || reg2.test($password)){
                        $("span#password_error").html("有被盗风险,建议使用字母、数字和符号两种及以上组合");
                        $(".msg-paw-icon").css("display","none");
                        $(".paw-tip i").addClass("icon-w");
                        $(".paw-tip i").removeClass("icon-r");
                        $(".paw-tip i").removeClass("icon-s");
                        $("#password").css("border","1px solid #ddd");
                        $("span#password_error").css("color","#ddd");
                             if((reg1.test($password) && $password.length >= 11) || (reg2.test($password) && $password.length >= 11)){
                                $(".msg-paw-icon").css("display","block");
                                $("#password").css("border","1px solid #ddd");
                                $("span#password_error").css("color","#ddd");
                             }
                    }else if(reg3.test($password)) {  
                        $("span#password_error").html("安全度中,可以使用三种以上的组合来提高安全度");
                        $(".msg-paw-icon").css("display","block");
                        $(".paw-tip i").removeClass("icon-w");
                        $(".paw-tip i").removeClass("icon-s");
                        $(".paw-tip i").addClass("icon-r");
                        $("#password").css("border","1px solid #ddd");
                        $("span#password_error").css("color","#ddd");
                    }else if(reg4.test($password) && ($password.length.length>8)) {  
                        $("span#password_error").html("你的密码很安全");
                         $(".msg-paw-icon").css("display","block");
                         $(".paw-tip i").removeClass("icon-w");
                         $(".paw-tip i").removeClass("icon-r");
                         $(".paw-tip i").addClass("icon-s");
                         $("#password").css("border","1px solid #ddd");
                        $("span#password_error").css("color","#ddd");
                    }else {  
                         $("span#password_error").html("你的密码很安全");
                         $(".paw-tip i").removeClass("icon-w");
                         $(".paw-tip i").removeClass("icon-r");
                         $(".paw-tip i").addClass("icon-s");                        
                         $(".msg-paw-icon").css("display","block");
                         $("#password").css("border","1px solid #ddd");
                         $("span#password_error").css("color","#ddd");
                    }
            }else{
                 $("#password").css("border","1px solid #ddd");
                 $("span#password_error").css("color","#ddd");
                 $("span#password_error").html("建议使用字母，数字和符号两种以上组合，6-20个字符");
                 $(".msg-paw-icon").css("display","none");
                 $(".paw-tip i").removeClass("icon-w");
                 $(".paw-tip i").removeClass("icon-r");
                 $(".paw-tip i").removeClass("icon-s");
                 $(".paw-tip i").removeClass("user-error-error");
                 $(".paw-tip i").addClass("user-error-help");

            }     
        }
    });
    
    //确认密码
    var flag3 = false;
    $('input#passwords').on({
       'focus': function () {
            var $passwords = $("input#passwords").val();
            var regex = /^[\u4E00-\u9FA5A-Za-z0-9_-]*$/;
	       if (!$.trim($passwords) == "") {
            }else{
                $("#passwords").css("border","1px solid #ddd");
                $("span#passwords_error").css("color","#ddd");
                $(".paws-tip i").addClass("user-error-help");
                $("span#passwords_error").html("请再次输入密码");
            };
        },
         'blur': function () {
            var $password = $("input#password").val();
            var $passwords = $("input#passwords").val();
            if ($.trim($passwords) == "") {
                $("span#passwords_error").html("");
                $(".paws-tip i").removeClass("user-error-help");
                $(".paws-tip i").removeClass("user-error-error");
                $("#passwords").css("border","1px solid #ddd");
            }else if($passwords == $password){
                    //alert("成功");
                    $(".paws-tip i").removeClass("user-error-error");
                    $(".paws-tip i").removeClass("user-error-help");
                    $("span#passwords_error").html("");
                    $("#passwords").css("border","1px solid #ddd");
                    $(".msg-paws-icon").css("display","block");     
                    flag3 = true;
                    // alert(flag3+"确认密码");     
                }else{
                    $("#passwords").css("border","1px solid red");
                    $("span#passwords_error").css("color","red");
                    $("span#passwords_error").html("两次输入密码不一致");
                    $(".paws-tip i").addClass("user-error-error");
                    $(".msg-paws-icon").css("display","none");
                }
            
        }
    });
    
    //邮箱验证
    var flag4 = false;
    $('input#mail').on({
        'focus': function () {
            var $mail = $("input#mail").val(); 
            if (!$.trim($mail) == "") {             
            }else{
                $("#mail").css("border","1px solid #ddd");
                $("span#mail_error").css("color","#ddd");
                $(".mail-tip i").addClass("user-error-help");
                $("span#mail_error").html("完成验证,可以使用该邮箱登陆和找回密码");
            };
        },
         'blur': function () {
            var $mail = $("input#mail").val();
            var regex =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if ($.trim($mail) == "") {
                $("span#mail_error").html("");
                $(".mail-tip i").removeClass("user-error-help");
                $(".mail-tip i").removeClass("user-error-error");
                $("#mail").css("border","1px solid #ddd");
            }else if(regex.test($mail)){    
                $(".phone-warp").css("border","1px solid transparent");
                $("#mail").css("border","1px solid #ddd");
                $(".msg-mail-icon").css("display","block");
                $("span#mail_error").html("");
                $(".mail-tip i").removeClass("user-error-help");
                $(".mail-tip i").removeClass("user-error-error");
                $("span#mail_error").css("color","#ddd");
                flag4 = true;
                	$.ajax({ 
				        type:"GET",
				        dataType:"json",
				        url:'http://192.168.0.16:8080/eLink/user/checkUsername/'+$mail,
				        beforeSend: function () {
							$(".msg-mail-icon").css("display","none");							
						},
				        success: function(result) {
				             if(result.rtnCode == 1000)  {
				            	$("#mail").css("border","1px solid #ddd");
			 					$("span#mail_error").css("color","#ddd");
								$(".mail-tip i").removeClass("user-error-errors"); 
								$(".msg-mail-icon").css("display","block");
				                //alert(result.rtnMessage);
				            } else  {
				                $("#mail").css("border","1px solid red");
			 					$("span#mail_error").css("color","red");			 					
								$(".mail-tip i").addClass("user-error-error");
								$("span#mail_error").html("邮箱已经被注册，请重新注册");				 					
				            }
				        },
				         error:function(jqXHR){     
				           alert("发生错误：" + jqXHR.status)  
				        }  
		    		});
            }else{
                $("#mail").css("border","1px solid red");
                    $("span#mail_error").css("color","red");
                    $("span#mail_error").html("格式有误");
                    $(".mail-tip i").addClass("user-error-error");
                    $(".msg-mail-icon").css("display","none");  
            }
        }
    });
    
    //验证手机
    var flag5 = false;
    $('input#phone').on({
        'focus': function () {
            var $phone = $("input#phone").val();
            if ($.trim($phone) == "") {
            	$("span#phone_error").html("完成验证,可以用该手机登陆和找回密码");
            	 $(".phone-tip i").addClass("user-error-help");
            }else{
                $("#phone").css("border","1px solid #ddd");
                $("span#phone_error").css("color","#ddd");
                $(".phone-tip i").removeClass("user-error-error");
                $(".phone-tip i").addClass("user-error-help");
                $("span#phone_error").html("完成验证,可以用该手机登陆和找回密码");
            };
        },
         'blur': function () {
            var $phone = $("input#phone").val();
            var regex =/^1[3|4|5|7|8]\d{9}$/;
            if ($.trim($phone) == "") {
                $("span#phone_error").html("");
                $(".phone-tip i").removeClass("user-error-help");
                $(".phone-tip i").removeClass("user-error-error");
                $("#phone").css("border","1px solid #ddd");
            }else if(regex.test($phone)){
                $(".phone-warp").css("border","1px solid transparent");
                $("#phone").css("border","1px solid #ddd");
                $(".msg-phone-icon").css("display","block");
                $("span#phone_error").html("");
                $(".phone-tip i").removeClass("user-error-help");
                $(".phone-tip i").removeClass("user-error-error");
                $("span#phone_error").css("color","#ddd");
                flag5 = true;
                	$.ajax({ 
				        type:"GET",
				        dataType:"json",
				        url:'http://192.168.0.16:8080/eLink/user/checkPhone/'+$phone,
				        beforeSend: function () {
				        	$(".msg-phone-icon").css("display","none");
						},
				        success: function(result) {
				        	//alert("11")
				        	//alert(result.rtnCode);
				            if (result.rtnCode == 1000) {
				            	//alert("2");
				            	$("#phone").css("border","1px solid #ddd");
			 					$("span#phone_error").css("color","#ddd");
								$(".phone-tip i").removeClass("user-error-errors"); 
								$(".msg-phone-icon").css("display","block");
								
				                //alert(result.rtnMessage);
				            } else  {
				                $("#phone").css("border","1px solid red");
			 					$("span#phone_error").css("color","red");			 					
								$(".phone-tip i").addClass("user-error-error");
								$("span#phone_error").html("手机号已经被占用，请重新注册");								
				            } 
				        },
				         error:function(jqXHR){     
				           alert("发生错误：" + jqXHR.status)  
				        }  
		    		});
		    		
            }else{
                $("#phone").css("border","1px solid red");
                    $("span#phone_error").css("color","red");
                    $("span#phone_error").html("格式有误");
                    $(".phone-tip i").addClass("user-error-error");
                    $(".msg-phone-icon").css("display","none"); 
            }
        }       
    });
    
    //验证吗
    var flag6 = false;
    $('input#authcode').on({
        'focus': function () {
            var $authcode = $("input#authcode").val();    
            if (!$.trim($authcode) == "") {               
            }else{
                $("#authcode").css("border","1px solid #ddd");
                $("span#authcode_error").css("color","#ddd");
//              $(".authcode-tip i").addClass("user-error-help");
//              $("span#authcode_error").html("完成验证,可以使用该手机登陆和找回密码");
            };
        },       
         'blur': function () {
            var $authcode = $("input#authcode").val();
            var regex =/^[0-9 | A-Z | a-z]{4,6}/;
            if ($.trim($authcode) == "") {
                $("span#authcode_error").html("");
                $(".authcode-tip i").removeClass("user-error-help");
                $(".authcode-tip i").removeClass("user-error-error");
                $("#authcode").css("border","1px solid #ddd");
            }
            else if(regex.test($authcode)){               
                $("span#authcode_error").html("");
                $(".authcode-tip i").removeClass("user-error-help");
                $(".authcode-tip i").removeClass("user-error-error");
                $("#authcode").css("border","1px solid #ddd");
                flag6 = true; 
                	$.ajax({ 
				        type:"GET",
				        dataType:"json",
				        url:'http://192.168.0.16:8080/eLink/user/checkUsername/'+$authcode,
				        beforeSend: function () {
							$(".msg-phone-icon").css("display","none");							
						},
				        success: function(result) {
				             if (result.rtnCode == 1000) {
				            	$("#phone").css("border","1px solid #ddd");
			 					$("span#phone_error").css("color","#ddd");								
				                //alert(result.rtnMessage);
				            } else {
				            	$("#authcode").css("border","1px solid red");
			 					$("span#mail_error").css("color","red");
								$("span#authcode_error").html("");
				            } 
				        },
				         error:function(jqXHR){     
				           alert("发生错误：" + jqXHR.status)  
				        }  
		    		});
            }
            else{
                    $("#authcode").css("border","1px solid red");
                    $("span#authcode_error").css("color","red");
                    $("span#authcode_error").html("验证码不正确或者已失效");
                    $(".authcode-tip i").addClass("user-error-error");
            }
        }              
    });
    
    //手机验证码
    var flag7 = false;
    $('input#authcodes').on({       
        'focus': function () {
            var $authcodes = $("input#authcodes").val();            
            if (!$.trim($authcodes) == "") {
                $("#authcodes").css("border","1px solid #ddd");
                $("span#authcode-phone_error").html("");
                $(".authcode-tip-phone i").removeClass("user-error-error");                
            }else{
                $("#authcodes").css("border","1px solid #ddd");
            };
        },
         'blur': function () {
            var $authcodes = $("input#authcodes").val();
            var regex =/^[0-9]{6}/;
            if ($.trim($authcodes) == "") {
                $("span#authcode-phone_error").html("");
                $(".authcode-tip-phone i").removeClass("user-error-help");
                $(".authcode-tip-phone i").removeClass("user-error-error");
                $("#authcodes").css("border","1px solid #ddd");
            }
            else if(regex.test($authcodes)){
                $("span#authcode-phone_error").html("");
                $(".authcode-tip-phone i").removeClass("user-error-help");
                $(".authcode-tip-phone i").removeClass("user-error-error");
                $("#authcodes").css("border","1px solid #ddd");                
                flag7 = true; 
                	$.ajax({ 
				        type:"GET",
				        dataType:"json",
				        url:'http://192.168.0.16:8080/eLink/user/checkUsername/'+$authcodes,
				        beforeSend: function () {					
						},
				        success: function(result) {
				            if(result.rtnCode == 1000) {
				            	$("#authcodes").css("border","1px solid #ddd");
			 					$("span#authcode-phone_error").css("color","#ddd");
				                //alert(result.rtnMessage);
				            } else {
				                $("#authcodes").css("border","1px solid red");
			 					$("span#authcode-phone_error").css("color","red");
								$("span#authcode_error").html("");
				            } 
				        },
				         error:function(jqXHR){     
				           alert("发生错误：" + jqXHR.status)  
				        }  
		    		});
            }
            else{
                    $("#authcodes").css("border","1px solid red");
                    $("span#authcode-phone_error").css("color","red");
                    $("span#authcode-phone_error").html("请输入六位数字的验证码");
                    $(".authcode-tip-phone i").addClass("user-error-error");
            
            }
        }
        
    });

    //邮箱验证码
    var flag8 = false;
    $('input#meadoce').on({
        'focus': function () {
            var $meadoce = $("input#meadoce").val();
            if (!$.trim($meadoce) == "") {
                $("#meadoce").css("border","1px solid #ddd");
                $("span#authcode-meadoce_error").html("");
                $(".authcode-tip-meadoce i").removeClass("user-error-error");
            }else{
                $("#meadoce").css("border","1px solid #ddd");
            };
        },
        'blur': function () {            
            var $meadoce = $("input#meadoce").val();
            var regex =/^[0-9]{6}/;
            if ($.trim($meadoce) == "") {
                $("span#authcode-phone_error").html("");
                $(".authcode-tip-phone i").removeClass("user-error-help");
                $(".authcode-tip-phone i").removeClass("user-error-error");
                $("#meadoce").css("border","1px solid #ddd");
            }
            else if(regex.test($meadoce)){                              
                $("span#authcode-phone_error").html("");
                $(".authcode-tip-phone i").removeClass("user-error-help");
                $(".authcode-tip-phone i").removeClass("user-error-error");
                $("#meadoce").css("border","1px solid #ddd");
                flag8 = true; 
                	$.ajax({ 
				        type:"GET",
				        dataType:"json",
				        url:'http://192.168.0.16:8080/eLink/user/checkUsername/'+$meadoce,
				        beforeSend: function () {													
						},
				        success: function(result) {
				            if (responseStatus.checkUsernameSuccess == result.rtnCode) {
				            	$("#meadoce").css("border","1px solid #ddd");
			 					$("span#authcode-phone_error").css("color","#ddd");
				            } else if (responseStatus.checkUsernameFailed == result.rtnCode) {
				                $("#meadoce").css("border","1px solid red");
			                    $("span#authcode-phone_error").css("color","red");
			                    $("span#authcode-phone_error").html("请输入六位数字的验证码");
			                    $(".authcode-tip-phone i").addClass("user-error-error");            
				            } else {
								//alert("你是谁");
				            }
				        },
				         error:function(jqXHR){     
				           alert("发生错误：" + jqXHR.status)  
				        }  
		    		});
            }
            else{
                    $("#meadoce").css("border","1px solid red");
                    $("span#authcode-phone_error").css("color","red");
                    $("span#authcode-phone_error").html("请输入六位数字的验证码");
                    $(".authcode-tip-phone i").addClass("user-error-error");            
            }
        }        
    });


    //获取短信验证倒计时
    var validCode=true;
    $("#phone_code").click (function  () {
        var $phone = $("input#phone").val();
        var regex =/^1[3|4|5|7|8]\d{9}$/;
        var $authcode = $("input#authcode").val();
        var regexs =/^[0-9 | A-Z | a-z]{4,6}/;
            if(!regex.test($phone) || $.trim($phone) == ""){
                $("#phone").css("border","1px solid red");
                $("span#phone_error").css("color","#ddd");
            }else if(!regexs.test($authcode) || $.trim($authcode) == ""){
                $(".msg-authcode").css("border","1px solid red");
                $("span#authcode_error").css("color","red");                
            }
            else if(regex.test($phone) && regexs.test($authcode)){
                var time=30;
                var code=$(this);
                if (validCode) {
                    validCode=false;
                    code.addClass("aclick");
                    var t=setInterval(function  () {
                        time--;
                        code.html(time+"秒后重新获取");
                        if (time==0) {
                            clearInterval(t);
                        code.html("重新获取");
                            validCode=true;
                        code.removeClass("aclick");
                        }
                    },1000)
                }
              } 
        })

    //获取邮箱短信验证倒计时
    var validCode=true;
    $("#meadoce_code").click (function  () {
        var $mail = $("input#mail").val();
        var regex =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var $authcode = $("input#authcode").val();
        var regexs =/^[0-9 | A-Z | a-z]{4,6}/;
            if(!regex.test($mail) || $.trim($mail) == ""){
                $("#mail").css("border","1px solid red");               
                $("#phone_error").css("color","#ddd");
            }else if(!regexs.test($authcode) || $.trim($authcode) == ""){
                $(".msg-authcode").css("border","1px solid red");
                $("span#authcode_error").css("color","red");                
            }
            else if(regex.test($mail) && regexs.test($authcode)){
                var time=30;
                var code=$(this);
                if (validCode) {
                    validCode=false;
                    code.addClass("aclick");
                    var t=setInterval(function  () {
                        time--;
                        code.html(time+"秒后重新获取");
                        if (time==0) {
                            clearInterval(t);
                        code.html("重新获取");
                            validCode=true;
                        code.removeClass("aclick");
                        }
                    },1000)
                }
              } 
        })


    //判断是否满足所有条件
    $("button.logins").on({'click':function(){
        $("input.form-account").each(function(){
            var $val = $(this).val();
            if($.trim($val) == ""){
                if(!($(this).parent().parent().css("display") == "none")){
                    $(this).focus();
                    $(this).css("border","1px solid red");
                    //$(this).parent().next().find("span.error").css("color","red");
                    return false;
                }
            }
		})          
            if($(".em-warp").css("display") == "none"){
                flag4 = true;
            }
            if($(".meadoce").css("display") == "none"){
                flag8 = true;
            }
            if($(".authcodes").css("display") == "none"){                
                flag7 = true;
            }
            //如果返回都为true  执行提交
           if($(".authcodes").css("display") == "block"){ 
               if(flag&&flag2&&flag3&&flag5&&flag6&&flag7){
//                  $("form.register-form").submit();
//                  window.location="reg3.html";
//				var _this=this;
//				_this.disable=true;
//				$(_this).css("background-position","right");
					$.ajax({  
				        type: "POST",      
				        url: "",      
				        data:$("form").serialize(),
				        beforeSend:function(){
				        	$(".msg-user-icon").css("display","block");
							$(".msg-user-icon").css("background","url(../img/loading.gif) no-repeat");
				        },
				        success: function(data){  
				            if(data==1){
				               $(".msg-user-icon").css("display","block");
				               $(".msg-user-icon").css("background","url(../img/icon.png) no-repeat 0px -117px");
				               $(".msg-user-icon").html("注册成功请登录");
				               //_this.disable=false;
							  //$(_this).css("background-position","left");
				               setTimeout(function(){
				               	//这里可以写成功后注册框几秒后消失
				               	//$("span#usernam_error").css("display","none");
				               },1500)
							}else{
				              // alert("抱歉！用户名已存在！");
				                $("span#usernam_error").html("抱歉！用户名已存在！");
				                $("#username").css("border","1px solid #ff9911");
						 		$("span#usernam_error").css("color","#ff9911");
								$(".user-tip i").addClass("user-error-errors");               
				            }   
				        }            
			    }); 
               }
           }else if(flag&&flag2&&flag3&&flag4&&flag6&&flag8){
//              $("form.register-form").submit();
//              window.location="reg3.html";
           }
    }})

    //显示隐藏      
    $("#e-Phone").click(function(){
        $(".msg-phone").css("display","none");
        $(".authcodes").css("display","none");
        $(".orPhone").css("display","none");
        $(".mail-tip").css("display","block");
        $(".phone-warp").css("display","none");
        $(".meadoce").css("display","block");
        $(".authcode-tip-phone").css("display","none");
        $(".authcode-tip-meadoce").css("display","block");
        $(".phone-tip").css("display","none");
        $(".msg-mail").css("display","block");    
    });
    $("#e-mail").click(function(){
        $(".msg-phone").css("display","block");
        $(".authcodes").css("display","block");
        $(".orPhone").css("display","block");
        $(".mail-tip").css("display","none");
        $(".phone-warp").css("display","block");
        $(".meadoce").css("display","none");
        $(".authcode-tip-phone").css("display","block");
        $(".authcode-tip-meadoce").css("display","none");
        $(".msg-mail").css("display","none");
        $(".phone-tip").css("display","block");    
    });
	
	//验证用户名是否存在
//	var username=$("#username").val();
//	if(!username == ""){
//		$.ajax({  
//	        type: "POST",      
//	        url: "",      
//	        data: "username="+username,
//	        beforeSend:function(){
//	        	$(".msg-user-icon").css("display","block");
//				$(".msg-user-icon").css("background","url(../img/loading.gif) no-repeat");
//	        },
//	        success: function(data){  
//	            if(data=="true"){     
//	               //alert("恭喜您！用户名没有被使用！");
//	               $(".msg-user-icon").css("display","block");
//	               $(".msg-user-icon").css("background","url(../img/icon.png) no-repeat 0px -117px");
//	               alert("验证通过的用户名为true");
//	               return true;
//				}else{
//	              // alert("抱歉！用户名已存在！");
//	                $("span#usernam_error").html("抱歉！用户名已存在！");
//	                $("#username").css("border","1px solid #ff9911");
//			 		$("span#usernam_error").css("color","#ff9911");
//					$(".user-tip i").addClass("user-error-errors");               
//	            }   
//	        }            
//	    });     
	//}//检验用户名结束
		
	//验证手机是否存在
//	var phone=$("#phone").val();
//	if(!phone == ""){
//		$.ajax({  
//	        type: "POST",      
//	        url: "",      
//	        data: "phone="+phone,
//	        beforeSend:function(){
//	        	$(".msg-phone-icon").css("display","block");
//				$(".msg-phone-icon").css("background","url(../img/loading.gif) no-repeat");
//	        },
//	        success: function(data){  
//	            if(data=="true"){     
//	               //alert("恭喜您！用户名没有被使用！");
//	               $(".msg-phone-icon").css("display","block");
//	               $(".msg-phone-icon").css("background","url(../img/icon.png) no-repeat 0px -117px");
//				   alert("验证通过的手机号为true");
//	               return true;
//	            }else{
//	              // alert("抱歉！用户名已存在！");
//	                $("span#phone_error").html("抱歉！手机号已存在！");
//	                $(".msg-phone").css("border","1px solid #ff9911");
//			 		$("span#phone_error").css("color","#ff9911");
//					$(".phone-tip i").addClass("user-error-errors");               
//	            }   
//	        }            
//	    });     
	//}//检验手机结束
		
	//验证邮箱是否存在
//	var mail=$("#mail").val();
//	if(!mail == ""){
//		$.ajax({  
//	        type: "POST",      
//	        url: "",      
//	        data: "mail="+mail,
//	        beforeSend:function(){
//	        	$(".msg-mail-icon").css("display","block");
//				$(".msg-mail-icon").css("background","url(../img/loading.gif) no-repeat");
//	        },
//	        success: function(data){  
//	            if(data=="true"){     
//	               //alert("恭喜您！用户名没有被使用！");
//	               $(".msg-mail-icon").css("display","block");
//	               $(".msg-mail-icon").css("background","url(../img/icon.png) no-repeat 0px -117px");
//					alert("验证通过的邮箱为true");
//	               return true;
//	            }else{
//	              // alert("抱歉！邮箱已存在！");
//	                $("span#mail_error").html("抱歉！邮箱已存在！");
//	                $("#mail").css("border","1px solid #ff9911");
//			 		$("span#mail_error").css("color","#ff9911");
//					$(".mail-tip i").addClass("user-error-errors");               
//	            }   
//	        }            
//	    });     
//	}//检验邮箱结束
	
	
	//登陆页面
	$("input#login_user").keyup(function(){
		var login_user=$("#login_user").val();
		if($.trim(login_user) != ""){
			$(".clear-btn").css("display","block");
			$(".itme").css("border","1px solid #ddd");
			$(".user_password").html(""); 
		}
	});
	$(".clear-btn").click(function(){
		$("#login_user").val("");
		$(".clear-btn").css("display","none");
	});
	
	$("input#login_password").keyup(function(){
		var login_user=$("#login_password").val();
		if($.trim(login_password) != ""){				
			$(".clear-btn2").css("display","block");
			$(".itme").css("border","1px solid #ddd");
			$(".user_password").html(""); 
		}
	});

	$(".clear-btn2").click(function(){
		if ($("input#login_password").attr("type") == "password") {
	            $("input#login_password").prop("type", "text")
	        }
	        else {
	            $("input#login_password").prop("type", "password")
	    }
		
	});

    //找回密码或者判断密码输入的一致性
	$(".determine").click(function(){
		
		var back_paw=$("#backpaw").val();
		var back_paws=$("#backpaws").val();
		if($.trim(back_paw)=="" ||$.trim(back_paws)==""){
			$(".determine-msg").html("两次输入的密码不一致，请重新输入");
			$(".new-pw").css("border","1px solid red");
		}
		else if(back_paw != back_paws){
			$(".determine-msg").html("两次输入的密码不一致，请重新输入");
			$(".new-pw").css("border","1px solid red");
		}else{
			window.location="reg.html";
		}
	});

	$("input#backpaw").keyup(function(){	
			$(".determine-msg").html("");
			$(".new-pw").css("border","1px solid #ddd");	
	});
	$("input#backpaws").keyup(function(){		
			$(".determine-msg").html("");
			$(".new-pw").css("border","1px solid #ddd");	
	});
	$(".back-icon-1").click(function(){
		if ($("input#backpaw").attr("type") == "password") {
	            $("input#backpaw").prop("type", "text")
	        }
	        else {
	            $("input#backpaw").prop("type", "password")
	    }	
	});
	$(".back-icon-2").click(function(){
		if ($("input#backpaws").attr("type") == "password") {
	        $("input#backpaws").prop("type", "text")
	        }
	        else {
	        $("input#backpaws").prop("type", "password")
	    }	
	});
	//找回密码密码强度
	$("#backpaw").on({
		'keyup':function(){
			var $backpaw=$("#backpaw").val();
	        var reg1 = /^[0-9]+$/;  
	        var reg2 = /^[a-zA-Z]+$/; 
	        var reg3 = /^[a-zA-Z0-9]+$/;
	        var reg4=/[~!@#\$%^&*\(\)\{\};,.`\?\/'"]+/;
	        if(reg1.test($backpaw) || reg2.test($backpaw)){
	           $(".back-tip-1").addClass("tip");   
	        }else if(reg3.test($backpaw)){
	        	 $(".back-tip-2").addClass("tip");	
	        }else if(reg4.test($backpaw) && $backpaw.length>5){
	        	//alert("1");
	        	$(".back-tip-3").addClass("tip");
	        	$(".back-tip-2").addClass("tip");
	        	$(".back-tip-1").addClass("tip"); 
	        }
	       
		}
	});
	
 	//找回密码获取验证码
	var validCode=true;
	$(".codes").click (function  () {
		var $username=$("input#for_username").val();
		var regex =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var regex1 =/^1[3|4|5|7|8]\d{9}$/;
			if($.trim($username) == "" ){
		 		$(".msg-error").css("color","red");
		 		$(".item-form1").css("border","1px solid red");
				$(".msg-error").css("visibility","initial");				
			}else if(regex.test($username) || regex1.test($username)){
				var time=30;
				var code=$(this);
				if (validCode) {
					validCode=false;
					code.addClass("alink");
					var t=setInterval(function  () {
						time--;
						code.html(time+"秒后重新获取");
						if (time==0) {
							clearInterval(t);
						code.html("重新获取");
							validCode=true;
						code.removeClass("alink");
						}
					},1000)
				}
			}  
		})
	
	//密码找回,手机号或邮箱账号
	$('input#for_username').on({
		'focus': function () {
		var $username=$("input#for_username").val();
			if($.trim($username) == "" ){
		 	$(".msg-error").css("visibility","hidden");
		 	$(".item-form1").css("border","1px solid #ddd");
			}else{
				$(".msg-error").css("visibility","hidden");
				$(".item-form1").css("border","1px solid #ddd");
			}
		},
		'blur': function () {
			var $username=$("input#for_username").val();
			var $regex_phone =/^1[3|4|5|7|8]\d{9}$/;		
			var $regex_email =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if($regex_phone.test($username) || $regex_email.test($username)){
					$(".msg-error").css("color","#ddd");
				    $(".msg-error").css("visibility","hidden");
				    $(".item-form1").css("border","1px solid #ddd");
				}else{
					$(".msg-error").css("color","red");
				    $(".msg-error").css("visibility","initial");
				    $(".item-form1").css("border","1px solid red");
				}
			}
		});
		
		//密码找回验证码和手机号或邮箱账号
		$('input#text').on({
			'focus': function () {					
			    $(".reg-error").css("visibility","hidden");
				$(".reg-error").css("color","#ddd");
				$("#text").css("border","1px solid #ddd");
		},
		'blur': function () {
			var $text=$("input#text").val();
			if($.trim($text) == "" || $text.length!=6){
			 	$(".reg-error").css("visibility","initial");
			 	$("span.reg-error").html("请输入正确的验证码");
			 	$(".reg-error").css("color","red");
			 	$("#text").css("border","1px solid red");
			}else{
				$(".reg-error").css("visibility","hidden");
				$(".reg-error").css("color","#ddd");
				$("#text").css("border","1px solid #ddd");
			}
		}
	});

	
	 //搜索显示切换
    $(function(e) {
	   var $area = $('.search-area'),
            $showhide = $('.showhide-search'),
            $input = $('.search-input');      
        $('.course-nav-hd').on('click', '.showhide-search', function (event){
            var isShow = $(this).attr('data-show');
            if( isShow == 'no'){
                show()
                $input.focus();
                $input.keyup(function(){
                	$(".search-result").css("display","block");
                });
                $(".search-input").css("border","1px solid #bcbcbc");
            }else{
            	if($input.val()==""){
            		hide()
            	}
            }                    
            return false;
        })        
        $('.course-nav-hd').on('click', '.search-area', function (event){
            return false;
        })         
        $(document).on('click', function (){
            if( $input.val() != ''){
                hide()
            }else{
            	hide()
            }
        })       
        var show = function (){
            $showhide.attr('data-show', 'yes')
            $area.show(1, function (){ $area.removeClass('min') })
        }     
        var hide = function (){
            $showhide.attr('data-show', 'no')
            $area.fadeOut('slow', function (){
                $area.addClass('min')
            })
        }
    })
	
	//点击显示当前状态
	$(".course-nav-item").click(function(){
		$(this).addClass("on").siblings().removeClass("on");	
	})
	
	$(".newest").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
	})
	
	$(".hide-text").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
	})
	
	$(".page a").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
	})
	
	
	//免费视频的选项卡切换
	$(".price-left-tab ul li").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
		var _index=$(".price-left-tab ul li").index(this);
		$(".price-left-bd").eq(_index).show().siblings().hide();
	})
	//免费视频弹窗
	//弹出立即报名窗口 
	  $('.oper-bar .oper-sign').on('click', function(event){ 	  
	    if( $(event.target).is($('.oper-sign')) ) {
	    	 $('.popup').addClass('is-visible');
	    }
	  }); 
	  //关闭弹出窗口 
	  $('.cancel').on('click', function(event){ 
	      $('.popup').removeClass('is-visible'); 
	  }); 
	  //弹出报名成功窗口
	  $('.go').on('click', function(event){ 	  
	    if( $(event.target).is($('.go')) ) {
	    	 $('.alert-box').addClass('is-visible');
	    	 $('.popup').removeClass('is-visible');
	    }
	  }); 
	  //关闭弹出窗口 
	  $('.alert-click').on('click', function(event){ 
	      $('.alert-box').removeClass('is-visible');
	      window.location="free-course2.html";
	  }); 
	  //使用Esc键关闭弹出窗口 
	  $(document).keyup(function(event){ 
	    if(event.which=='27'){ 
	      $('.popup').removeClass('is-visible'); 
	    } 
	  });
	  
	//已关注
	var $follow=1;
	$(".follow").on('click',function(){
		if($follow==1){
			$(this).html("已关注").css({"background":"#ececec"});
			$(this).css("color","#666");
			$follow++;
		}else if($follow!=1){		
			$(this).html("+ 关注").css({"background":"#49b4e1"});
			$(this).css("color","#fff");
			$follow=1;
		}
	})
	
	//评价星际
    var stepW = 24;
    var stars = $("#star > li");
    $("#showb").css("width",0);
    stars.each(function(i){
        $(stars[i]).click(function(e){
            var n = i+1;
            $("#showb").css({"width":stepW*n});
            $(this).find('a').blur();
            return stopDefault(e);
        });
    });
	function stopDefault(e){
	    if(e && e.preventDefault)
	           e.preventDefault();
	    else
	           window.event.returnValue = false;
	    return false;
	}
	
//发表评论 
$(".textarea").on({
	'focus':function(){
		$(".pl-input-warp").addClass("pl-input-warps");	
		$(".pl-input-warp").css("border","1px solid green");
	},
	'keyup':function(){		
		//$(".pl-input-warp").css("border","1px solid #d3dce0");
		var num=300-$(".textarea").val().length;
		if(num>=0){
			$(".pl-limit").html(num);
			//$(".pl-input-warp").css("border","1px solid #d3dce0");
		}else{
			$(".pl-limit").html(Math.abs(num)+300);
			$(".pl-input-warp").css("border","1px solid red");
			return false;
		}
  },
  'blur':function(){
  	$(".pl-input-warp").css("border","1px solid #d3dce0");
  	$(".pl-input-warp").removeClass("pl-input-warps");
  }
});
   		    
$(".input-btn-pl").click(function(){
	var $val=$(".textarea").val();
	var $val_length=$(".textarea").val().length;
	if($val == ""){
		$(".pl-input-warp").css("border","1px solid red");
		return false;
	}else if($val_length>300){
		return false;
	}else{
		alert("这里写成功后的东西");
	}
})

//视频缩进切换
var slide_flag = 1; //计数器
$('.open').on('click','.aaa',function(){					
	if(slide_flag == 1) { //第一次点击
		$(".video-list").animate({'right':'0'});
	    $(".video-warp").animate({'width':'80%'});
	    $(".aaa").css({"background":"red"},{"background":"url(../img/course_prev.png)"});
		slide_flag = 2;
	}else if(slide_flag == 2) { //第二次点击
		$(".video-list").animate({'right':'-305'});
        $(".video-warp").animate({'width':'100%'});
        $(".aaa").css({"background":"#434343"});
		slide_flag = 1;
	}
})
//	//评论过滤
//	$(".f-radio").click(function(){
//		$(this).addClass("checked").siblings().removeClass("checked");
//		var _index=$(".f-radio").index(this);
//		//$(".price-left-bd").eq(_index).show().siblings().hide();
//	})
})






























